//
//  FilePathUtils.swift
//  HappyToSee
//
//  Created by Wade on 2024/7/2.
//

import Foundation

class FilePathUtils{
    static var documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
    
    static var cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first
    
    static var documentPathURL = FileManager.default.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).first
    
    static  var cachePathURL = FileManager.default.urls(for: FileManager.SearchPathDirectory.cachesDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).first
    
    static  var tempPath = NSTemporaryDirectory()
    
    static  var tempPathURL = URL(fileURLWithPath: tempPath)
    
    
    static func documentPathWithPath(filePath:String)->String{
        return documentPath! + filePath
    }
    
    static func documentURLWithPath(filePath:String)->URL{
        return URL(fileURLWithPath: documentPathWithPath(filePath: filePath))
    }
    
    
    static func cachePathWithPath(filePath:String)->String{
        let path = cachePath! + "/" + filePath
        try! FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true)
        return path
    }
    
    static func cacheURLWithPath(filePath:String)->URL{
        return URL(fileURLWithPath: cachePathWithPath(filePath: filePath))
    }
    
    static func tepmPathWithPath(filePath:String)->String{
        return tempPath + filePath
    }
    
    static func tempURLWithPath(filePath:String)->URL{
        return URL(fileURLWithPath: tepmPathWithPath(filePath: filePath))
    }
}
